package com.xyd.Servlet;

import com.xyd.Biz.AddressBiz;
import com.xyd.Biz.CommodityBiz;
import com.xyd.Biz.FatherOrderBiz;
import com.xyd.Biz.Impl.AddressBizImpl;
import com.xyd.Biz.Impl.CommodityBizImpl;
import com.xyd.Biz.Impl.FatherOrderBizImpl;
import com.xyd.Biz.Impl.OrderFormBizImpl;
import com.xyd.Biz.OrderFormBiz;
import com.xyd.Entity.Commodity;
import com.xyd.Entity.FatherOrder;
import com.xyd.Entity.OrderForm;
import com.xyd.Entity.TAddress;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author：李思傧
 * @version 1.0
 * 在父订单列表通过点击修改进入到父订单详情页面
 */
@WebServlet("/html/manage/FatherOrderDetailsServlet")
public class FatherOrderDetailsServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        long fatherOrderId = Long.parseLong(request.getParameter("fatherOrderId"));



        FatherOrderBiz fatherOrderBiz = new FatherOrderBizImpl();
        FatherOrder fatherOrder = fatherOrderBiz.selectFatherOrderByID(fatherOrderId);


        OrderFormBiz orderFormBiz = new OrderFormBizImpl();
        List<OrderForm> orderFormList = orderFormBiz.selectSonOrder(fatherOrderId);

        CommodityBiz commodityBiz = new CommodityBizImpl();
        List<Commodity> commodityList = commodityBiz.getAllCommodity();

        AddressBiz addressBiz = new AddressBizImpl();
        TAddress address = addressBiz.getAddressByUser(fatherOrder.getUser());

        Map<String,Object> FatherOrderAndAddresssMap = new HashMap<>();
        FatherOrderAndAddresssMap.put("fatherOrder",fatherOrder);
        FatherOrderAndAddresssMap.put("address",address);
        FatherOrderAndAddresssMap.put("orderFormList",orderFormList);
        FatherOrderAndAddresssMap.put("commodityList",commodityList);



        request.setAttribute("FatherOrderAndAddresssMap",FatherOrderAndAddresssMap);
        //response.sendRedirect("order-modify.jsp");
        request.getRequestDispatcher("order-modify.jsp").forward(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
